# 3.10 Temperature and Humidity Sensor ## 3.10.1 Overview AHT20 temperature and humidity sensor adopts I2C interface and 20Bit ADC, and its operating voltage is 2V-5V. It features small volume, stable performance and high precision (accuracy: temperature ±0.3℃, humidity ±2%RH). So it is widely used in smart home, consumer electronics, medical and automotive. The sensor is stable and can work in harsh environments. ## 3.10.2 Schematic Diagram ![image-20240701144311341](./media/6-10-2.png) ATH20 temperature and humidity sensor transmits data via I2C interface, and it works according to resistive and capacitive technology. It detects the temperature because the material's conductivity changes with temperature, and it reflects humidity through the change in the capacitance value. The temperature measurement range is -40 ° C to +85 ° C with accuracy of ±0.3 ° C, and the humidity range is 0% ~ 100%RH ±2%RH. Besides, it features high accuracy, high reliability and long-term stability. With I2C protocol, ATH20 provides real-time and accurate temperature and humidity data under a variety of environmental conditions. ## 3.10.3 Code Blocks ![image-20240702083642783](./media/j34.png) This block reads reads the temperature and humidity values. But it only reads one of them at once. ## 3.10.4 Test Code ### 3.10.4.1 Build Code There are two ways to upload the code: directly open the code file we provide; or manually build blocks. **Directly open the code file we provide:** 1. Click ![](./media/j68.png) and choose `Load from your computer` ![](./media/j67.png) 2. We have already downloaded the codes on computer desktop, so open the file and choose `3-10-aht20.sb3` **Manually build blocks:** 1. In ![events](./media/events.png), find ![j1](./media/j1.png) block. 2. In ![serial](./media/serial.png), find ![j12](./media/j12.png) block and set baud rate to 9600, and put it under ![j1](./media/j1.png). 3. In ![control](./media/control.png), drag ![j2](./media/j2.png).![6-4-4-1-1](./media/6-2-4-1-1.png) ![6-2](./media/6-2-4-1-2.png) 4. In ![serial](./media/serial.png), put ![j13](./media/j13.png) in ![j2](./media/j2.png), and set to print “T: ” in no-warp mode. 5. Add another ![image-20240701141959486](./media/6-9-4-1-1.png) and set to no-warp 6. In ![image-20240702084630903](./media/temp.png), put ![j14](./media/j34.png) into the printing box of ![j13](./media/6-9-4-1-1.png) to read “Temperature”. ![6-10](./media/6-10-4-1-1.png) 7. Duplicate ![6-10](./media/6-10-4-1-2.png) and change “T: ” into “ RH:”(the two spaces separates the two values to be output). Read “Humidity” value. 8. Add a delay of 1S for better observing the results. **Complete Test Code** ![6-10-4-1-3](./media/6-10-4-1-3.png) ### 3.10.4.2 Test Result After uploading code, the serial monitor prints temperature and humidity values and refreshes the results per second. ![6-10](./media/6-10-4-2.png)